package com.gin.no_gay_alliance.viewmodel;

import android.os.Parcel;
import android.os.Parcelable;

import com.gin.common.utils.TimeUtils;
import com.gin.nga.enums.UserBuffType;
import com.gin.nga.response.field.user.UserBuff;

/**
 * 用户Buff
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/7 00:19
 **/
public class UserBuffModel implements Parcelable {
    public static final Creator<UserBuffModel> CREATOR = new Creator<UserBuffModel>() {
        @Override
        public UserBuffModel createFromParcel(Parcel in) {
            return new UserBuffModel(in);
        }

        @Override
        public UserBuffModel[] newArray(int size) {
            return new UserBuffModel[size];
        }
    };
    /**
     * 存疑，可能是操作记录id
     */
    public Long id;
    /**
     * buff类型id
     */
    public Integer typeId;
    /**
     * buff类型
     */
    public UserBuffType type;
    /**
     * 释放buff的用户id
     */
    public Long fromUserId;
    /**
     * 用户id
     */
    public Long userId;
    /**
     * buff开始时间
     */
    public String start;
    /**
     * buff结束时间
     */
    public String end;
    /**
     * 额外数据，可能为版面id，或道具的subType
     */
    public Long extraData;
    /**
     * 描述
     */
    public String description;
    /**
     * 被禁言的版面名称
     */
    public String forumName;

    public UserBuffModel(UserBuff buff) {
        id = buff.getId();
        typeId = buff.getTypeId();
        fromUserId = buff.getFromUserId();
        userId = buff.getUserId();
        start = TimeUtils.format(buff.getStart(), TimeUtils.SHORT_FORMATTER);
        end = TimeUtils.format(buff.getEnd(), TimeUtils.SHORT_FORMATTER);
        extraData = buff.getExtraData();
        description = buff.getDescription();
        forumName = buff.getForumName();

        if (typeId != null) {
            type = UserBuffType.findById(typeId);
        }
    }

    protected UserBuffModel(Parcel in) {
        if (in.readByte() == 0) {
            id = null;
        } else {
            id = in.readLong();
        }
        typeId = in.readInt();
        if (in.readByte() == 0) {
            fromUserId = null;
        } else {
            fromUserId = in.readLong();
        }
        if (in.readByte() == 0) {
            userId = null;
        } else {
            userId = in.readLong();
        }
        start = in.readString();
        end = in.readString();
        if (in.readByte() == 0) {
            extraData = null;
        } else {
            extraData = in.readLong();
        }
        description = in.readString();
        forumName = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (id == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(id);
        }
        dest.writeInt(typeId);
        if (fromUserId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(fromUserId);
        }
        if (userId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(userId);
        }
        dest.writeString(start);
        dest.writeString(end);
        if (extraData == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(extraData);
        }
        dest.writeString(description);
        dest.writeString(forumName);
    }
}
